//
// Copyright (c) 2011, Peter Lane
// Licensed under the Academic Free License version 3.0

package fan.swtChartWrapper;

import fan.fwt.*;
import fan.gfx.Color;
import fan.gfx.Font;
import fan.sys.*;
import org.eclipse.swt.*;
import org.eclipse.swtchart.ILegend;

public class LegendPeer {
  private ILegend _ilegend = null;

  public static LegendPeer make (fan.swtChartWrapper.Legend self) throws Exception {
    return new LegendPeer ();
  }

  public void setILegend (ILegend ilegend) {
    _ilegend = ilegend;
    _ilegend.setBackground (Fwt.get().color(_background));
    _ilegend.setForeground (Fwt.get().color(_foreground));
    _ilegend.setFont (Fwt.get().font(_font));
    _ilegend.setPosition  (Utility.toSwt (_position));
    _ilegend.setVisible (_visible);
  }

  private Color _background = Color.white;
  public Color background (fan.swtChartWrapper.Legend self) { return _background; }
  public void background (fan.swtChartWrapper.Legend self, Color v) {
    _background = v;
    if (_ilegend != null) _ilegend.setBackground (Fwt.get().color(_background));
  }

  private Color _foreground = Color.blue;
  public Color foreground (fan.swtChartWrapper.Legend self) { return _foreground; }
  public void foreground (fan.swtChartWrapper.Legend self, Color v) {
    _foreground = v;
    if (_ilegend != null) _ilegend.setForeground (Fwt.get().color(_foreground));
  }

  private Font _font = Desktop.sysFont().toSize (9);
  public Font font (fan.swtChartWrapper.Legend self) { return _font; }
  public void font (fan.swtChartWrapper.Legend self, Font f) {
    _font = f;
    if (_ilegend != null) _ilegend.setFont (Fwt.get().font(_font));
  }

  private Position _position = Position.right;
  public Position position (fan.swtChartWrapper.Legend self) { return _position; }
  public void position (fan.swtChartWrapper.Legend self, Position v) {
    _position = v;
    if (_ilegend != null) _ilegend.setPosition (Utility.toSwt (_position));
  }

  private boolean _visible = true;
  public boolean visible (fan.swtChartWrapper.Legend self) { return _visible; }
  public void visible (fan.swtChartWrapper.Legend self, boolean v) {
    _visible = v;
    if (_ilegend != null) _ilegend.setVisible (_visible);
  }
}
